#include "vertex_types.fxh"
#include "Samplers.fxh"
#include "globals.fxh"



float3 CalcReflectionVector(float3 ViewToPos, float3 Normal)
{
	return normalize(reflect(ViewToPos, Normal));
}


TNORMAL_REFLECTION_TEXTURED_VERTEX_PS RenderVS(TNORMAL_TEXTURED_VERTEX_VS IN)
{
	
    TNORMAL_REFLECTION_TEXTURED_VERTEX_PS OUT = (TNORMAL_REFLECTION_TEXTURED_VERTEX_PS )0;
    OUT.HPosition=mul(float4(IN.Position,1.0),g_WorldViewProjectionMatrix);
    OUT.UV=IN.UV;
    OUT.WorldNormal=mul(IN.Normal,(float3x3) g_WorldMatrix);
    OUT.WorldPosition=mul(float4(IN.Position,1.0), g_WorldMatrix);
	float3 EyeToVertex=normalize(OUT.HPosition.xyz-g_CameraPosition);
	OUT.Reflect=CalcReflectionVector(EyeToVertex,OUT.WorldNormal);
	
	
    return OUT;
}

float4 RenderPS(TNORMAL_REFLECTION_TEXTURED_VERTEX_PS IN) : COLOR
{
	
	float g_EnvironmentFactor = 0.8;

	float4 l_EnvirontmentColor = g_EnvironmentFactor*texCUBE(S0LinearSamplerCUBE, IN.Reflect);

    return l_EnvirontmentColor;
    
}



technique tecEnvironmentMap
{
    pass p0
    {        
        VertexShader =compile vs_3_0 RenderVS();
        PixelShader = compile ps_3_0 RenderPS();
    }
}

